{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "639a2bef",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import torch\n",
    "\n",
    "os.makedirs(os.path.join(\"..\",\"data\"), exist_ok = True)\n",
    "datafile = os.path.join(\"..\",\"data\",\"house_tiny.csv\")\n",
    "with open(datafile , 'w') as f:\n",
    "    f.write('Name,Alley,Price\\n')\n",
    "    f.write('NA,Pava,127500\\n')\n",
    "    f.write('2,turnel,106000\\n')\n",
    "    f.write('4,NA,178000\\n')\n",
    "    f.write('NA,NA,140000\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "62c3503e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Name</th>\n",
       "      <th>Alley</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>Pava</td>\n",
       "      <td>127500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.0</td>\n",
       "      <td>turnel</td>\n",
       "      <td>106000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>178000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Name   Alley   Price\n",
       "0   NaN    Pava  127500\n",
       "1   2.0  turnel  106000\n",
       "2   4.0     NaN  178000\n",
       "3   NaN     NaN  140000"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv(datafile)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "b57ca6af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(   Name   Alley\n",
       " 0   NaN    Pava\n",
       " 1   2.0  turnel\n",
       " 2   4.0     NaN\n",
       " 3   NaN     NaN,\n",
       " 0    127500\n",
       " 1    106000\n",
       " 2    178000\n",
       " 3    140000\n",
       " Name: Price, dtype: int64)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputs,outputs = data.iloc[:,0:2],data.iloc[:,2]\n",
    "inputs,outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "9cbe2678",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Name   Alley\n",
      "0   3.0    Pava\n",
      "1   2.0  turnel\n",
      "2   4.0     NaN\n",
      "3   3.0     NaN\n"
     ]
    }
   ],
   "source": [
    "inputs = inputs.fillna(inputs.mean())\n",
    "print(inputs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d6c07fc5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   Name  Alley_Pava  Alley_turnel  Alley_nan\n",
      "0   3.0           1             0          0\n",
      "1   2.0           0             1          0\n",
      "2   4.0           0             0          1\n",
      "3   3.0           0             0          1\n"
     ]
    }
   ],
   "source": [
    "inputs = pd.get_dummies(inputs, dummy_na = True)\n",
    "print(inputs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "f2c4da6c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([[3., 1., 0., 0.],\n",
       "         [2., 0., 1., 0.],\n",
       "         [4., 0., 0., 1.],\n",
       "         [3., 0., 0., 1.]], dtype=torch.float64),\n",
       " tensor([127500, 106000, 178000, 140000]))"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x,y = torch.tensor(inputs.values), torch.tensor(outputs.values)\n",
    "x,y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5e31be6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d219bac8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
